﻿/*
 *    Copyright © 2012 FPInst authors
 *
 *      This file is part of the FPInst project 
 *      (for more information, see: http://code.google.com/p/fpinst/).
 *
 *    FPInst is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    FPInst is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with FPInst.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Diagnostics;
using Cellum.Tools;

namespace RotSw
{
    public class MouseMessageFilter : IMessageFilter
    {
        public static RotSwControl ActualControl;
        private static int WM_MOUSEWHEEL = 0x020A;

        #region IMessageFilter Members

        [DebuggerStepThrough]
        public bool PreFilterMessage(ref Message m)
        {
            //Debug.Write(m.Msg);
            if (ActualControl != null)
            {
                if (m.Msg == WM_MOUSEWHEEL)
                {
                    Int64 wparam;
                    if (IntPtr.Size == 8)
                        wparam = m.WParam.ToInt64();
                    else
                        wparam = m.WParam.ToInt32();

                    short delta = (short)(wparam >> 16);
                    //Debug.Write(Utils.Hex16(wparam) + " : " + delta);
                    ActualControl.Wheel(delta);
                    return true;
                }

            }

            return false;
        }

        #endregion
    }
}
